//用于添加角色的表单
var addRoleForm = Ext.create("Ext.form.Panel", {
	header: false,
	width: 400,
	bodyPadding: 10,
	overflowX: 'hidden', //设置横向滚动条不显示
	overflowY: 'auto', //设置纵向滚动条超出高度显示
	defaultType: 'textfield',
	defaults: {
		anchor: '100%',
		labelWidth: 70,
		labelAlign: "right"
	},
	items: [{
		allowBlank: false,
		fieldLabel: '系统名',
		name: 'name',
		emptyText: '请以ROLE_开头'
	}, {
		allowBlank: false,
		fieldLabel: '中文名',
		name: 'chineseName',
		emptyText: '中文名',
	}, {
		xtype: 'fieldset',
		title: '是否继承已有角色',
		collapsed: true,
		checkboxToggle: true,
		items: [{
			xtype: 'grid',
			fieldLabel: '要继承的角色',
			name: 'role',
			header: false,
			store: Ext.data.StoreManager.lookup('roleListStore'),
			columns: [{
				text: '角色名称',
				dataIndex: 'chineseName',
				flex: 1
			}],
			selModel: addRoleFormGridCheckBox
		}]
	}],
	buttons: [{
		text: '添加',
		handler: function() {
			if(!addRoleForm.getForm().isValid())
				return;
			if(addRoleForm.getForm().findField('name').lastValue.substring(0, addRoleForm.getForm().findField('name').lastValue.indexOf('_')) != 'ROLE')
				Ext.Msg.alert('错误', '系统名输入不正确！要以"ROLE_"开头');
			else {
				addRoleForm.setDisabled(true);
				var selectArray = addRoleForm.down('grid').getSelectionModel().getSelected(); //得到被选择的行的数组
				var jsonArray = new Array();
				var object = new Object();
				Ext.each(selectArray.items, function(result) {
					jsonArray.push(result.data.id);
				});
				object['id']=Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");
				object['name'] = addRoleForm.getForm().findField('name').lastValue;
				object['chineseName'] = addRoleForm.getForm().findField('chineseName').lastValue;
				object['baseRoles'] = jsonArray;
				var json = Ext.JSON.encode(object);
				Ext.Ajax.request({
					url: zuulUrl+'/'+authServiceName+'/admin/role',
					method: 'post',
					params: {
						roleJson: json
					},
					success: function(response, opts) {
						if(response.responseText == 0)
							Ext.Msg.alert('错误','系统名已存在或者中文名已存在');
						else if(response.responseText == 1) {
							Ext.Msg.alert('成功', '添加成功！');
							Ext.data.StoreManager.lookup('roleListStore').reload();
						}
					},
					failure: function(response, opts) {
						console.log('server-side failure with status code ' + response.status);
					}
				});
				addRoleForm.setDisabled(false);
			}
		}
	}]
});

//用于添加和编辑用户是显示和填写基本信息的表单
var userBaseMsgForm = Ext.create("Ext.form.Panel", {
	header: false,
	//width: 400,
	bodyPadding: 10,
	defaultType: 'textfield',
	overflowX: 'hidden', //设置横向滚动条不显示
	overflowY: 'auto', //设置纵向滚动条超出高度显示
	defaults: {
		anchor: '100%',
		labelWidth: 70,
		labelAlign: "right"
	},
	items: [{
		allowBlank: false,
		fieldLabel: '用户名',
		name: 'username',
		emptyText: '用户名',
		margin:'0 0 20 0'
	}, {
		allowBlank: false,
		fieldLabel: '姓名',
		name: 'realName',
		emptyText: '姓名',
		margin:'0 0 20 0'
	}, {
		allowBlank: true,
		fieldLabel: '密码',
		name: 'password1',
		emptyText: '不填代表不修改',
		inputType: 'password',
		margin:'0 0 20 0'
	}, {
		allowBlank: true,
		fieldLabel: '再输入密码',
		name: 'password2',
		emptyText: '不填代表不修改',
		inputType: 'password',
		margin:'0 0 20 0'
	}]
});